﻿using FriendStar.Code;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using FriendStar.Application.VBaseData;
using FriendStar.Domain.Entity.VBaseData;
using System;

namespace FriendStar.Web.Areas.VBaseData.Controllers
{
    public class V_CPK_A1_BB_StoProStockCata_RBController : Controller
    {
        //
        // GET: /VBaseData/V_CPK_A1_BB_StoProStockCata_RB/
        private V_CPK_A1_BB_StoProStockCata_RBApp dutyApp = new V_CPK_A1_BB_StoProStockCata_RBApp();

        [HttpGet]
        [HandlerAjaxOnly]
        //public ActionResult GetGridJson(string keyword)
        //{
        //    var data = dutyApp.GetList(keyword);
        //    return Content(data.ToJson());
        //}
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetGridJson(Pagination pagination, string fAccountDate, string fProductionNO, string fProductionName, string fProCompanyNO, string FProductionTypeNO)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJson(pagination, fAccountDate, fProductionNO, fProductionName, fProCompanyNO, FProductionTypeNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        /// <summary>
        /// 价格调整Action
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="fAccountDate"></param>
        /// <param name="fProductionNO"></param>
        /// <param name="fProductionName"></param>
        /// <param name="fProCompanyNO"></param>
        /// <param name="FProductionTypeNO"></param>
        /// <returns></returns>
        public ActionResult GetGridJsonPrice(Pagination pagination, string fAccountDate, string dwbz, string FProductionNO, string FProductionName, string FProCompanyNO, string FProductionTypeNO, bool isCurrent)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonPrice(pagination, fAccountDate, dwbz, FProductionNO, FProductionName, FProCompanyNO, FProductionTypeNO, isCurrent, Configs.GetValue("UseUnit")),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        /// <summary>
        /// 入库统计Action
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="fAccountDate"></param>
        /// <param name="FHappenComName"></param>
        /// <param name="FProductionNO"></param>
        /// <param name="FProductionName"></param>
        /// <param name="FProCompanyNO"></param>
        /// <param name="FProductionTypeNO"></param>
        /// <param name="isCurrent"></param>
        /// <returns></returns>
        public ActionResult GetGridJsonInstoreStat(Pagination pagination, string fAccountDate, string FHappenComNO, string FProductionNO, string FProductionName, string FProCompanyNO, string FProductionTypeNO, bool isCurrent)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonInstoreStat(pagination, fAccountDate, FHappenComNO, FProductionNO, FProductionName, FProCompanyNO, FProductionTypeNO, isCurrent, Configs.GetValue("UseUnit")),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        public ActionResult GetGridJsonInstoreStatT(Pagination pagination, string fAccountDate, string FHappenComNO,bool isCurrent)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonInstoreStatT(pagination, fAccountDate, FHappenComNO,isCurrent, Configs.GetValue("UseUnit")),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        /// <summary>
        /// 销售统计action
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="fAccountDate"></param>
        /// <param name="FHappenComNO"></param>
        /// <param name="FProductionNO"></param>
        /// <param name="FProductionName"></param>
        /// <param name="FProCompanyNO"></param>
        /// <param name="FProductionTypeNO"></param>
        /// <param name="isCurrent"></param>
        /// <returns></returns>
        public ActionResult GetGridJsonSalesStat(Pagination pagination, string fAccountDate, string FHappenComNO, string FProductionNO, string FProductionName, string FProCompanyNO, string FProductionTypeNO, bool isCurrent)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonSalesStat(pagination, fAccountDate, FHappenComNO, FProductionNO, FProductionName, FProCompanyNO, FProductionTypeNO, isCurrent, Configs.GetValue("UseUnit")),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        /// <summary>
        /// 销售汇总
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="fAccountDate"></param>
        /// <param name="FHappenComNO"></param>
        /// <param name="isCurrent"></param>
        /// <returns></returns>
        public ActionResult GetGridJsonSalesStatT(Pagination pagination, string fAccountDate, string FHappenComNO,bool isCurrent)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonSalesStatT(pagination, fAccountDate, FHappenComNO, isCurrent, Configs.GetValue("UseUnit")),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }


        /// <summary>
        /// 批次查询action
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="FDocuNO"></param>
        /// <param name="FVoucherNo"></param>
        /// <param name="FHappenCompanyNO"></param>
        /// <param name="FProductionNO"></param>
        /// <param name="FProductionName"></param>
        /// <param name="FProCompanyNO"></param>
        /// <param name="FProductionTypeNO"></param>
        /// <returns></returns>
        public ActionResult GetGridBatchStoreStat(Pagination pagination,string FDocuNO, string FVoucherNo, string FHappenCompanyNO, string FProductionNO, string FProductionName, string FProCompanyNO, string FProductionTypeNO, string FStoreNO)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonBatchStoreStat(pagination, FDocuNO, FVoucherNo, FHappenCompanyNO, FProductionNO, FProductionName, FProCompanyNO, FProductionTypeNO, Configs.GetValue("UseUnit"), FStoreNO),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        /// <summary>
        /// 单据查询
        /// </summary>
        /// <param name="pagination"></param>
        /// <param name="FDocuNO"></param>
        /// <param name="FVoucherNo"></param>
        /// <param name="FTypeNO"></param>
        /// <param name="FHappenComNO"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="FProductionNO"></param>
        /// <param name="FProductionName"></param>
        /// <param name="FProCompanyNO"></param>
        /// <returns></returns>
        public ActionResult GetGridBillQueryStat(Pagination pagination, string FDocuNO, string FVoucherNo, string FTypeNO, string FHappenComNO, string startDate, string endDate, string FProductionNO, string FProductionName ,string FProCompanyNO)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonBillQueryStat(pagination, FDocuNO, FVoucherNo, FTypeNO, FHappenComNO, startDate, endDate, FProductionNO, FProductionName, FProCompanyNO, Configs.GetValue("UseUnit")),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        //入库清单查询
        public ActionResult GetGridInstockBill(Pagination pagination, string ManufactureLine, string startDate, string endDate, string FHappenComNO)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonInstockBill(pagination, ManufactureLine, startDate, endDate, FHappenComNO, Configs.GetValue("UseUnit")),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        //出库清单查询
        public ActionResult GetGridOutstockBill(Pagination pagination, string ManufactureLine, string startDate, string endDate, string FHappenComNO)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonOutstockBill(pagination, ManufactureLine, startDate, endDate, FHappenComNO, Configs.GetValue("UseUnit")),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }
        //入库汇总查询
        public ActionResult GetGridJsonInStockTotal(Pagination pagination, string ManufactureLine, string startDate, string endDate, string FHappenComNO,string FProductionTypeNO,string FProCompanyNO,string FProductionName,string FProductionNO)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonInStockTotal(pagination, ManufactureLine, startDate, endDate, FHappenComNO, FProductionTypeNO, FProCompanyNO, FProductionName, FProductionNO, Configs.GetValue("UseUnit")),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        public ActionResult GetGridJsonOutStockTotal(Pagination pagination, string ManufactureLine, string startDate, string endDate, string FHappenComNO,string FProductionTypeNO,string FProCompanyNO,string FProductionName,string FProductionNO)
        {
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonOutStockTotal(pagination, ManufactureLine, startDate, endDate, FHappenComNO, FProductionTypeNO, FProCompanyNO, FProductionName, FProductionNO, Configs.GetValue("UseUnit")),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        public ActionResult CalcStockCateSum(string date,bool isCurrent)
        {
            string useunit = Configs.GetValue("UseUnit");

            string userId = OperatorProvider.Provider.GetCurrent().UserName;

            var result = dutyApp.CalcStockCateSum(date, isCurrent, useunit, userId);

            return Content(result.ToJson());
        }

        public ActionResult GetGridJsonMateQutoCheck(Pagination pagination, string ManufactureLine, string ProduceLine,string ProductUnit, string ProduWorkshop, string FProductionNO, string Material, string FSign)
        {
            string useUnit = Configs.GetValue("UseUnit");
            var data = new
            {
                rows = dutyApp.GetParameterGridJsonMateQutoCheck(pagination, ManufactureLine, ProduceLine,ProductUnit, ProduWorkshop, FProductionNO, Material, FSign, useUnit ),
                total = pagination.total,
                page = pagination.page,
                records = pagination.records
            };
            return Content(data.ToJson());
        }

        public ActionResult GetGridJsonMateQutoCheckDo(int FSign)
        {
            string useUnit = Configs.GetValue("UseUnit");

            string curUser = OperatorProvider.Provider.GetCurrent().UserName;

            var data = dutyApp.GetParameterGridJsonMateQutoCheckDo(FSign,useUnit, curUser);
     
            return Content(data.ToJson());
        }

    }
}